diff options
Diffstat (limited to 'glucometerutils/support/lifescan.py')
-rw-r--r-- | glucometerutils/support/lifescan.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/glucometerutils/support/lifescan.py b/glucometerutils/support/lifescan.py index 4df0b8f..13529ec 100644 --- a/glucometerutils/support/lifescan.py +++ b/glucometerutils/support/lifescan.py @@ -10,43 +10,43 @@ from glucometerutils import exceptions class MissingChecksum(exceptions.InvalidResponse): - """The response misses the expected 4-digits checksum.""" - def __init__(self, response): - self.message = 'Response is missing checksum: %s' % response + """The response misses the expected 4-digits checksum.""" + def __init__(self, response): + self.message = 'Response is missing checksum: %s' % response class InvalidSerialNumber(exceptions.Error): - """The serial number is not as expected.""" - def __init__(self, serial_number): - self.message = 'Serial number %s is invalid.' % serial_number + """The serial number is not as expected.""" + def __init__(self, serial_number): + self.message = 'Serial number %s is invalid.' % serial_number class MalformedCommand(exceptions.InvalidResponse): - def __init__(self, message): - exceptions.InvalidResponse.__init__( - self, 'Malformed command: %s' % message) + def __init__(self, message): + exceptions.InvalidResponse.__init__( + self, 'Malformed command: %s' % message) def crc_ccitt(data): - # type: (bytes) -> int - """Calculate the CRC-16-CCITT with LifeScan's common seed. + # type: (bytes) -> int + """Calculate the CRC-16-CCITT with LifeScan's common seed. - Args: - data: (bytes) the data to calculate the checksum of + Args: + data: (bytes) the data to calculate the checksum of - Returns: - (int) The 16-bit integer value of the CRC-CCITT calculated. + Returns: + (int) The 16-bit integer value of the CRC-CCITT calculated. - This function uses the non-default 0xFFFF seed as used by multiple - LifeScan meters. - """ - crc = 0xffff + This function uses the non-default 0xFFFF seed as used by multiple + LifeScan meters. + """ + crc = 0xffff - for byte in data: - crc = (crc >> 8) & 0xffff | (crc << 8) & 0xffff - crc ^= byte - crc ^= (crc & 0xff) >> 4 - crc ^= (((crc << 8) & 0xffff) << 4) & 0xffff - crc ^= (crc & 0xff) << 5 + for byte in data: + crc = (crc >> 8) & 0xffff | (crc << 8) & 0xffff + crc ^= byte + crc ^= (crc & 0xff) >> 4 + crc ^= (((crc << 8) & 0xffff) << 4) & 0xffff + crc ^= (crc & 0xff) << 5 - return (crc & 0xffff) + return (crc & 0xffff) |